package com.newcapec.servlet;

import com.newcapec.bean.UserEntity;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:显示系统主界面的servlet类
 * @Author:yangshupeng
 * @Date: 2022/3/21 22:11
 * @Version:1.0
 */
@WebServlet("/index.html")
public class ShowIndexHtmlServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求和响应的内容的编码格式
        /*req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");*/
        //从session对象获取userEntity对象
        UserEntity userEntity = (UserEntity) req.getSession().getAttribute("user");
        if (userEntity == null) {
            //如果用户为空，说明用户没登录，那么页面跳转到登录页面
            resp.sendRedirect("login.html?type=3");
            return;
        }
        //请求转发
        req.getRequestDispatcher("WEB-INF/jsp/index.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
